Ext.namespace("Project.Prepare");

Project.Prepare.panel = function() {
	//Task.FeedBack.win.instance = new Task.FeedBack.win();
	this.projectCode = new Ext.form.TextField({
        fieldLabel: '项目编号',
        width: 200
    });
	this.projectName = new Ext.form.TextField({
        fieldLabel: '项目名称',
        width: 200
    });
	this.leader = new Ext.form.TextField({
        fieldLabel: '参与领导',
        width: 400
    });
	this.projectArea = new Ext.form.ComboBox({
		width: 200,
		fieldLabel: '所属区域',
        store: new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: OMS.INFO_TYPE2
        }),
        value: 0,
        valueField: 'value',
        displayField: 'name',
        editable: false,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});
	this.projectType = new Ext.form.ComboBox({
		width: 200,
		fieldLabel: '项目类型',
        store: new Ext.data.ArrayStore({
        	fields: ['value', 'name'],
        	data: OMS.INFO_INSTANCY_LEVEL2
        }),
        value: 0,
        valueField: 'value',
        displayField: 'name',
        editable: false,
        mode: 'local',
        triggerAction: 'all',
        selectOnFocus: true
	});
	
	this.submitTime = new Ext.form.DateField({
		fieldLabel: '立项时间',
        dateFormat:'Y-m-d',
        dateConfig: {
            altFormats:'Y-m-d',
            allowBlank: false,   
            disabled:true 
       }
	});
	this.lastFinishTime = new Ext.form.DateField({
		fieldLabel: '预计结束时间',
        dateFormat:'Y-m-d',
        dateConfig: {
            altFormats:'Y-m-d',
            allowBlank: false,   
            disabled:true 
       }
	});
	this.txtTaskTitle = new Ext.form.TextField({
		width: 150
	});
	this.dtStart = new Ext.form.DateField({
		width: 85,
		format: 'Y-m-d'
	});
	this.dtEnd = new Ext.form.DateField({
		width: 85,
		format: 'Y-m-d'
	});
	this.cmStart = new Ext.form.DateField({
		width: 85,
		format: 'Y-m-d'
	});
	this.cmEnd = new Ext.form.DateField({
		width: 85,
		format: 'Y-m-d'
	});
    this.btnSearch = new Ext.Toolbar.Button({
        iconCls: 'icon-search',
        text: '查找',
        tooltip: {text: '查找任务'},
        handler: this.queryTask,
        scope: this
    });
    
    this.btnAgree = new Ext.Toolbar.Button({
        iconCls: 'icon-accept',
        text: '接受',
        tooltip: {text: '接受任务处理'},
        handler: this.sendTask,
        scope: this
    });
    
    this.btnBack = new Ext.Toolbar.Button({
        iconCls: 'icon-return',
        text: '退回',
        tooltip: {text: '任务退回'},
        handler: this.backTask,
        scope: this
    });
	this.store = new Ext.data.Store({
		proxy: new Ext.data.HttpProxy({
			url: '../task/searchTaskExe.form?timesnap=' + Date.parse(new Date())
		}),
		reader: new Ext.data.JsonReader({
			root: 'result',
			totalProperty: 'total',
			fields: ['TASK_ID','TASK_EXE_ID','TASK_TITLE', 'TASK_DATE','USER_NAME','TASK_COMPLETE_DATE',
			 'TASK_DISPATCHER','TASK_CONTENT','TASK_STATUS','TASK_ORIGIN','TASK_NOTE','TASK_EXECUTOR',
			 'TASK_EXE_DISPATCHER_ID','TASK_EXE_USER_ID','TASK_EXE_STATUS','DIS_NAME']
		}),listeners:{
			 beforeload :{    
	    	  	fn : function(thiz,options){
       	          Ext.apply(thiz.baseParams,
       	          { 
       	          	 status:[0],
       	             taskTitle:this.txtTaskTitle.getValue(),
			  		 dtStart:this.dtStart.getValue()?this.dtStart.getValue().format('Y-m-d'):'',
			  		 dtEnd:this.dtEnd.getValue()?this.dtEnd.getValue().format('Y-m-d'):'',
			  		 cmStart:this.cmStart.getValue()?this.cmStart.getValue().format('Y-m-d'):'',
			  		 cmEnd:this.cmEnd.getValue()?this.cmEnd.getValue().format('Y-m-d'):''
       	          });    
              },
              scope:this 
	    	}
		}
	});
	this.renderDays = function(value){
		var date = Date.parseDate(value.substring(0,10),"Y-m-d");
		var days = parseInt((date.getTime()-new Date().getTime())/(1000*60*60*24));
		if(days<0)
			return "<font color='red'>逾期"+(-days)+"天</font>";
		else
			return "<font size=1 >还剩"+days+"天</font>";
	};
	this.renderTaskStatus = function(value){
		return OMS.TASKSEXESTATUS[value];
	};
	this.sm =  new Ext.grid.CheckboxSelectionModel();
	this.colModel = new Ext.grid.ColumnModel({
	    defaults: {
	        width: 100,
	        sortable: true,
	        align: 'center'
	    },
	    columns: [
	    	this.sm ,
			{header: 'TASK_ID', width: 50, hidden: true, dataIndex: 'TASK_ID'},
			{header: '项目编号', width: 200, dataIndex: 'TASK_TITLE'},
			{header: '项目名称', dataIndex: 'TASK_DATE'},
			{header: '所在区域', dataIndex: 'TASK_COMPLETE_DATE'},
			{header: '项目类型', dataIndex: 'DIS_NAME'},
			{header: '估算金额', dataIndex: 'TASK_COMPLETE_DATE',renderer:this.renderDays},
			{header: '预计时间', dataIndex: 'TASK_EXE_STATUS',renderer:this.renderTaskStatus}
	    ]
	});
	
	this.gridPanel = new Ext.grid.GridPanel({
		region: 'center',
		cm:this.colModel,
		sm:this.sm ,
		store:this.store,
		loadMask: true,
		stripeRows: true, 
		autoHeight:true,
        loadMask: {msg: '加载中，请稍候...'},
        bbar:new Ext.PagingToolbar({
			 pageSize: 5,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
        viewConfig: { forceFit: true },
        listeners:{
      		  rowdblclick : function( grid, rowIndex,e){ 
        			Task.FeedBack.win.instance.initDetail(grid.store.getAt(rowIndex).data);
					Task.FeedBack.win.instance.show();
			}
       }
	});
	this.custName = new Ext.form.TextField({
		fieldLabel:'客户名称',
		width: 300
	});
	this.employeeCount = new Ext.form.TextField({
		fieldLabel:'员工人数'
	});
	this.linkman = new Ext.form.TextField({
		fieldLabel:'联系人姓名'
	});
	this.tel = new Ext.form.TextField({
		fieldLabel:'办公电话'
	});
	this.phone = new Ext.form.TextField({
		fieldLabel:'手机'
	});
	this.email = new Ext.form.TextField({
		fieldLabel:'EMAIL'
	});
	
	this.custInfo = new Ext.form.FieldSet({
		title: '客户信息',
		layout:'table',
		collapsed:false,
		layoutConfig:{columns:4},
		items:[
		       {colspan:2,layout:'form',items:[this.custName]},
		       {colspan:2,layout:'form',items:[this.employeeCount]},
		       {colspan:1,layout:'form',items:[this.linkman]},
		       {colspan:1,layout:'form',items:[this.tel]},
		       {colspan:1,layout:'form',items:[this.phone]},
		       {colspan:1,layout:'form',items:[this.email]},
		]
	});
	this.projectAim = new Ext.form.TextField({
		fieldLabel:'项目目标',
		width: 500
	});
	this.serviceContent = new Ext.form.TextArea({
		fieldLabel: '服务要求',
		width:500,
		height:50,
		autoScroll:true
	});
	this.actionContent = new Ext.form.TextArea({
		fieldLabel: '实现功能',
		width:500,
		height:50,
		autoScroll:true
	});
	this.serviceProvide = new Ext.form.TextArea({
		fieldLabel: '业务提供',
		width:500,
		height:50,
		autoScroll:true
	});
	this.remark = new Ext.form.TextArea({
		fieldLabel: '备注',
		width:500,
		height:50,
		autoScroll:true
	});
	this.requestInfo = new Ext.form.FieldSet({
		title: '需求信息',
		layout:'table',
		collapsed:false,
		layoutConfig:{columns:4},
		items:[
		       {colspan:4,layout:'form',items:[this.projectAim]},
		       {colspan:4,layout:'form',items:[this.serviceContent]},
		       {colspan:4,layout:'form',items:[this.actionContent]},
		       {colspan:4,layout:'form',items:[this.serviceProvide]},
		       {colspan:4,layout:'form',items:[this.remark]}
		]
	});
	this.custName = new Ext.form.TextField({
		fieldLabel:'对手名称',
		width: 200
	});
	this.employeeCount = new Ext.form.TextField({
		fieldLabel:'项目负责人'
	});
	this.linkman = new Ext.form.TextField({
		fieldLabel:'联系人姓名'
	});
	
	this.txtContent5 = new Ext.form.TextArea({
		fieldLabel: '优势',
		width:500,
		height:50,
		autoScroll:true
	});
	this.txtContent6 = new Ext.form.TextArea({
		fieldLabel: '劣势',
		width:500,
		height:50,
		autoScroll:true
	});
	this.requestInfo2 = new Ext.form.FieldSet({
		title: '竞争对手信息',
		layout:'table',
		collapsed:false,
		layoutConfig:{columns:6},
		items:[
		       {colspan:6,layout:'form',items:[this.txtContent]}
		]
	});
	this.formFieldSet = new Ext.form.FieldSet({
		title:'立项信息',
		layout:'table',
		layoutConfig:{columns:4},
		items:[
			{colspan:2,layout:'form',items:[this.projectCode]},
        	{colspan:2,layout:'form',items:[this.projectName]},
        	{colspan:2,layout:'form',items:[this.projectArea]},
        	{colspan:2,layout:'form',items:[this.projectType]},
        	{colspan:2,layout:'form',items:[this.submitTime]},
        	{colspan:2,layout:'form',items:[this.lastFinishTime]},
        	{colspan:4,layout:'form',items:[this.leader]},
        	{colspan:4,layout:'form',items:[this.custInfo]},
        	{colspan:4,layout:'form',items:[this.requestInfo]}
		]
	});	
	
	
	
	this.form = new Ext.form.FormPanel({
        frame:true,
        height:360,
       	layout:'form',
       	autoScroll:true,
        items: [this.formFieldSet]
    });
	Project.Prepare.panel.superclass.constructor.call(this, {
		title:'草稿箱',
		layout:'column',
		items:[
				{columnWidth:1,
					layout:'form',
					items:[
						   this.gridPanel
				  ]},
				{columnWidth:1,
           			layout:'form',
           			items:[
           			       this.form
			      ]}],
		listeners:{
			render:this.queryTask
		}
	});
};
Ext.extend(Project.Prepare.panel, Ext.Panel, {
	showAddTask:function(){
		if(!Task.Add.win.instance)
			Task.Add.win.instance = new Task.Add.win();
		Task.Add.win.instance.show();
	
	},
	queryTask :function(){ 
		this.store.load({
			params:{
				start : 0,
				limit : 5,
				status:[0],
				 taskTitle:this.txtTaskTitle.getValue(),
			  	 dtStart:this.dtStart.getValue()?this.dtStart.getValue().format('Y-m-d'):'',
				 dtEnd:this.dtEnd.getValue()?this.dtEnd.getValue().format('Y-m-d'):'',
		  		 cmStart:this.cmStart.getValue()?this.cmStart.getValue().format('Y-m-d'):'',
		  		 cmEnd:this.cmEnd.getValue()?this.cmEnd.getValue().format('Y-m-d'):''
				}
		});
	}
});


